package com.xtx.controller.user;

import com.xtx.dto.AddAddressDTO;
import com.xtx.entity.Address;
import com.xtx.entity.Province;
import com.xtx.result.Result;
import com.xtx.service.AddressService;
import com.xtx.vo.AddressVo;
import com.xtx.vo.CountyVo;
import com.xtx.vo.MarketVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/address")
@Slf4j
public class AddressController {

    @Autowired
    private AddressService addressService;

    @GetMapping("/province")
    public Result<List<Province>> getProvinceList() {
        List<Province> provinceList = addressService.getProvinceList();
        log.info("获取省信息接口");
        return Result.success(provinceList);
    }
    @GetMapping("/market/{id}")
    public Result<List<MarketVo>> getMarketList(@PathVariable Integer id) {
        List<MarketVo> marketList = addressService.getMarketList(id);
        log.info("获取市信息接口");
        return Result.success(marketList);
    }
    @GetMapping("/county/{id}")
    public Result<List<CountyVo>> getCountyList(@PathVariable Integer id) {
        List<CountyVo> CountyList = addressService.getCountyList(id);
        log.info("获取市信息接口");
        return Result.success(CountyList);
    }
    @PostMapping
    public Result addAddress(@RequestBody AddAddressDTO addAddressDTO) {
        log.info("添加地址接口");
        addressService.addAddress(addAddressDTO);
        return Result.success();
    }
    @GetMapping("/{id}")
    public Result<List<AddressVo>> getAddressList(@PathVariable Integer id) {
        log.info("获取地址列表接口");
        List<AddressVo> addressList = addressService.getAddressList(id);
        return Result.success(addressList);
    }
}
